package cn.net.sdjx.common;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

public class Pagination<T> implements Serializable {

	private static final long serialVersionUID = 6092247575580174370L;
	
	//当前页号
	public int pageNum;
	//每页大小
	public int numPerPage;
	//总记录数
	public int totalCount;
	//总页数
	public int totalPage;
	//返回结果
	public List<T> result = Collections.emptyList();

	public int getPageNum() {
		return pageNum;
	}
	
	public void setPageNum(int pageNum) {
		if(pageNum < 1){
			this.pageNum = 1;
		}
		if(pageNum>this.getTotalPage()){
			this.pageNum=this.getTotalPage();
		}
		this.pageNum = pageNum;
	}
	
	public int getNumPerPage() {
		return numPerPage;
	}
	
	public void setNumPerPage(int numPerPage) {
		if(numPerPage < 1){
			this.numPerPage = 10;
		}
		this.numPerPage = numPerPage;
	}
	
	public int getTotalCount() {
		return totalCount;
	}
	
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	
	public int getTotalPage(){
		if(numPerPage < 1){
			this.numPerPage = 10;
		}
		int i = (totalCount - 1)/numPerPage + 1;
		return i <= 0 ? 0 : i;
	}
	
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	
	public List<T> getResult() {
		return result;
	}
	
	public void setResult(List<T> result) {
		this.result = result;
	}
	
	public int getStartIndex(){
		int i = (pageNum - 1) * numPerPage;
		return i <= 0 ? 0 : i;
	}
	
	public int getEndIndex(){
		int i = pageNum * numPerPage - 1;
		return i <=0 ? 0: i;
	}
	
}
